home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 3 / Amiga Format CD03 (1996-07-04)(Future Publishing)(GB)(Track 1 of 6)[!][issue 1996-08].iso / comms / netsoftware / nethandler.lha / NetHandler / handler / file.c < prev    next >
C/C++ Source or Header  |  1989-09-16  |  6KB  |  196 lines

  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  2. /* |_o_o|\\ Copyright (c) 1987, 1988 The Software Distillery.  All Rights  */
  3. /* |. o.| || Reserved.  This program may not be distributed without the    */
  4. /* | .  | || permission of the authors:                            BBS:    */
  5. /* | o  | ||   John Toebes     Doug Walker    Dave Baker                   */
  6. /* |  . |//                                                                */
  7. /* ======                                                                  */
  8. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  9. /* File Manipulation  */
  10. /*  ActDelete ActRename ActSetProtection ActSetComment */
  11. #include "handler.h"
  12.  
  13. void ActDelete(global, pkt)
  14. GLOBAL global;
  15. struct DosPacket *pkt;              /* a pointer to the dos packet sent    */
  16. /* Arg1: Lock    */
  17. /* Arg2: Name    */
  18. {
  19.    NETPTR nlock;
  20.    struct FileLock *flock;
  21.    BUG(("ActDelete\n"));
  22.  
  23.    /* Can't delete in the root of NET: */
  24.    if((!(flock=(struct FileLock *)pkt->dp_Arg1) || 
  25.        !(nlock=(NETPTR)flock->fl_Key)->RDevice))
  26.    {
  27.       if(ParseName(global, (char *)pkt->dp_Arg2, &nlock, global->RP.Data) || 
  28.          !nlock)
  29.       {
  30.          /* Either he is trying to delete a node or he got the name wrong */
  31.          pkt->dp_Res1 = DOS_FALSE;
  32.          pkt->dp_Res2 = (nlock ? ERROR_OBJECT_IN_USE
  33.                                : ERROR_WRITE_PROTECTED);
  34.          return;
  35.       }
  36.       BUGBSTR("RmtDelete: Sending to node ", nlock->NetNode->name);
  37.    }
  38.    else
  39.       MBSTR(pkt->dp_Arg2, global->RP.Data);
  40.  
  41.    BUGBSTR("RmtDelete: remote node name =", global->RP.Data);
  42.  
  43.    global->RP.Type = pkt->dp_Type;
  44.    global->RP.Arg1 = (LONG)nlock->RPtr;
  45.    global->RP.DLen = BSTRLEN(global->RP.Data)+1;
  46.    if(global->RP.DLen == 1) global->RP.DLen = 0;
  47.  
  48.    RemotePacket(global, nlock);
  49. }
  50.  
  51. void ActRename(global,pkt)
  52. GLOBAL global;
  53. struct DosPacket *pkt;              /* a pointer to the dos packet sent    */
  54. /* Arg1: FromLock    */
  55. /* Arg2: FromName    */
  56. /* Arg3: ToLock        */
  57. /* Arg4: ToName        */
  58. {
  59.    NETPTR nlock, nlock2;
  60.    struct FileLock *flock;
  61.    char *tmpchar;
  62.  
  63.    BUG(("ActRename\n"));
  64.  
  65.    /* See if it is a local lock */   
  66.    if((!(flock=(struct FileLock *)pkt->dp_Arg1) || 
  67.        !(nlock=(NETPTR)flock->fl_Key)->RDevice))
  68.    {
  69.       if(ParseName(global, (char *)pkt->dp_Arg2, &nlock, global->RP.Data) ||
  70.          !nlock)
  71.       {
  72.          /* Trying to rename a node, or something that doesn't exist */
  73.          pkt->dp_Res1 = DOS_FALSE;
  74.          pkt->dp_Res2 = ERROR_OBJECT_NOT_FOUND;
  75.          return;
  76.       }
  77.    }
  78.    else
  79.       MBSTR(pkt->dp_Arg2, global->RP.Data);
  80.  
  81.    /* See if the second lock is a local lock */   
  82.    if((!(flock=(struct FileLock *)pkt->dp_Arg3) || 
  83.        !(nlock2=(NETPTR)flock->fl_Key)->RDevice))
  84.    {
  85.       if(ParseName(global, (char *)pkt->dp_Arg4, &nlock, 
  86.           global->RP.Data+FILENAMELEN) || !nlock2)
  87.       {
  88.          /* See if they are trying to rename a node */
  89.          if(global->RP.Data[0] == 1 && global->RP.Data[1] == ':')
  90.          {
  91.             tmpchar = global->RP.Data+FILENAMELEN;
  92.             if(tmpchar[0] > RNAMELEN) tmpchar[0] = RNAMELEN;
  93.             MBSTR(tmpchar, nlock->NetNode->name);
  94.          }
  95.          else
  96.          {
  97.             pkt->dp_Res1 = DOS_FALSE;
  98.             pkt->dp_Res2 = (nlock2 ? ERROR_OBJECT_EXISTS
  99.                                    : ERROR_RENAME_ACROSS_DEVICES);
  100.          }
  101.          return;
  102.       }
  103.    }
  104.    else
  105.       MBSTR(pkt->dp_Arg4, global->RP.Data+FILENAMELEN);
  106.  
  107.    /* Check for rename across devices */
  108.    if(nlock->NetNode != nlock2->NetNode)
  109.    {
  110.       pkt->dp_Res1 = DOS_FALSE;
  111.       pkt->dp_Res2 = ERROR_RENAME_ACROSS_DEVICES;
  112.       return;
  113.    }
  114.  
  115.    global->RP.Type = pkt->dp_Type;
  116.    global->RP.Arg1 = (LONG)nlock->RPtr;
  117.    global->RP.Arg3 = (LONG)nlock2->RPtr;
  118.    global->RP.DLen = FILENAMELEN + BSTRLEN(global->RP.Data+FILENAMELEN)+1;
  119.  
  120.    RemotePacket(global, nlock);
  121. }
  122.  
  123. void ActSetProtection(global, pkt)
  124. GLOBAL global;
  125. struct DosPacket *pkt;              /* a pointer to the dos packet sent */
  126. /* Arg1: Unused */
  127. /* Arg2: Lock */
  128. /* Arg3: Name */
  129. /* Arg4: Mask of protection */
  130. {
  131.    struct FileLock *flock;
  132.    NETPTR nlock;
  133.  
  134.    BUG(("ActSetProtection\n"));
  135.  
  136.    BUGBSTR("File to protect: ", pkt->dp_Arg3);
  137.  
  138.    if((!(flock=(struct FileLock *)pkt->dp_Arg2) || 
  139.        !(nlock=(NETPTR)flock->fl_Key)->RDevice))
  140.    {
  141.       /* Local lock - protection not implemented yet */
  142.       pkt->dp_Res1 = DOS_TRUE;
  143.       return;
  144.    }
  145.  
  146.    global->RP.Type = pkt->dp_Type;
  147.    global->RP.Arg2 = (LONG)nlock->RPtr;
  148.    MBSTR(pkt->dp_Arg3, global->RP.Data);
  149.    global->RP.Arg4 = pkt->dp_Arg4;
  150.    global->RP.DLen = BSTRLEN(global->RP.Data)+1;
  151.    if(global->RP.DLen == 1) global->RP.DLen = 0;
  152.  
  153.    RemotePacket(global, nlock);
  154. }
  155.  
  156. void ActSetComment(global,pkt)
  157. GLOBAL global;
  158. struct DosPacket *pkt;              /* a pointer to the dos packet sent       */
  159. /* Arg1: Unused */
  160. /* Arg2: Lock */
  161. /* Arg3: Name */
  162. /* Arg4: Comment */
  163. {
  164.    struct FileLock *flock;
  165.    NETPTR nlock;
  166.  
  167.    BUG(("ActSetComment\n"));
  168.  
  169.    BUGBSTR("File to Comment: ", pkt->dp_Arg3);
  170.    BUGBSTR("New Comment Str: ", pkt->dp_Arg4);
  171.  
  172.    if((!(flock=(struct FileLock *)pkt->dp_Arg2) || 
  173.        !(nlock=(NETPTR)flock->fl_Key)->RDevice))
  174.    {
  175.       /* Can't SetComment local nodes */
  176.       pkt->dp_Res1 = DOS_TRUE;
  177.       return;
  178.    }
  179.  
  180.    global->RP.Type = pkt->dp_Type;
  181.    global->RP.Arg2 = (LONG)nlock->RPtr;
  182.    MBSTR(pkt->dp_Arg3, global->RP.Data);
  183.    MBSTR(pkt->dp_Arg4, global->RP.Data+FILENAMELEN);
  184.    global->RP.DLen = FILENAMELEN + BSTRLEN(global->RP.Data+FILENAMELEN)+1;
  185.  
  186.    RemotePacket(global, nlock);
  187. }
  188.  
  189. void ActSetFileDate(global, pkt)
  190. GLOBAL global;
  191. struct DosPacket *pkt;
  192. {
  193.    pkt->dp_Res1 = DOS_FALSE;
  194.    pkt->dp_Res2 = ERROR_NODE_DOWN;
  195. }
  196.